using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2024-09-30
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 公差校验表
    /// </summary>
    [Verify]
    [Route("business/ToleranceCheckInfo")]
    [ApiExplorerSettings(GroupName = "business")]
    public class ToleranceCheckInfoController : BaseController
    {
        /// <summary>
        /// 公差校验表接口
        /// </summary>
        private readonly IToleranceCheckInfoService _ToleranceCheckInfoService;

        public ToleranceCheckInfoController(IToleranceCheckInfoService ToleranceCheckInfoService)
        {
            _ToleranceCheckInfoService = ToleranceCheckInfoService;
        }

        /// <summary>
        /// 查询公差校验表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "tolerancecheckinfo:list")]
        public IActionResult QueryToleranceCheckInfo([FromQuery] ToleranceCheckInfoQueryDto parm)
        {
            var response = _ToleranceCheckInfoService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询公差校验表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "tolerancecheckinfo:query")]
        public IActionResult GetToleranceCheckInfo(int Id)
        {
            var response = _ToleranceCheckInfoService.GetInfo(Id);
            
            var info = response.Adapt<ToleranceCheckInfoDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加公差校验表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "tolerancecheckinfo:add")]
        [Log(Title = "公差校验表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddToleranceCheckInfo([FromBody] ToleranceCheckInfoDto parm)
        {
            var modal = parm.Adapt<ToleranceCheckInfo>().ToCreate(HttpContext);

            var response = _ToleranceCheckInfoService.AddToleranceCheckInfo(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新公差校验表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "tolerancecheckinfo:edit")]
        [Log(Title = "公差校验表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateToleranceCheckInfo([FromBody] ToleranceCheckInfoDto parm)
        {
            var modal = parm.Adapt<ToleranceCheckInfo>().ToUpdate(HttpContext);
            var response = _ToleranceCheckInfoService.UpdateToleranceCheckInfo(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除公差校验表
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "tolerancecheckinfo:delete")]
        [Log(Title = "公差校验表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteToleranceCheckInfo([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_ToleranceCheckInfoService.Delete(idArr));
        }

    }
}